# 定义小票信息
order_number = "DH202311010001"
time = "2023-11-01 20:56:15"


# 商品列表，每个元素是（名称，数量，单价，金额）
products = [
    ("金士顿U盘8G", 1, 40.00, 40.00),
    ("胜创16GTF卡", 1, 50.00, 50.00),
    ("读卡器", 1, 8.00, 8.00),
    ("网线2米", 1, 5.00, 5.00)
]


# 计算总数和总额
total_count = len(products)
total_amount = sum(product[3] for product in products)
discounted_amount = total_amount
received = total_amount
change = 0.00
cashier = "管理员"


# 生成商品列表部分
product_lines = []
for product in products:
    name, quantity, price, amount = product
    # 使用格式化字符串确保对齐
    product_line = f"{name.ljust(12)} {quantity:2d}    {price:6.2f}  {amount:6.2f}"
    product_lines.append(product_line)

product_section = "\n".join(product_lines)


# 定义分隔符
separator = "-" * 40


# 生成小票内容
receipt = f"""===== 购物凭证 =====
单号: {order_number}
时间: {time}

{separator}
名称          数量  单价    金额
{separator}
{product_section}
{separator}

总数: {total_count}        总额: {total_amount:.2f}
折后总额: {discounted_amount:.2f}
实收: {received:.2f}        找零: {change:.2f}

{separator}
收银: {cashier}
===== 感谢惠顾 =====
"""
# 打印小票
print(receipt)
